package main

import (
	"fmt"
	"github.com/jinzhu/configor"
	"gomod/route"
)

var Config = struct {
	APPName string `default:"app name"`

	DB struct {
		Name     string
		User     string `default:"root"`
		Password string `required:"true" env:"DBPassword"`
		Port     uint   `default:"3306"`
	}

	Contacts []struct {
		Name  string
		Email string `required:"true"`
	}
}{}

func main() {
	fmt.Println("使用外部包测试:", configor.Config{})
	fmt.Println("使用项目内包测试:", route.User{Name: "张三"})

	//// Enable debug mode or set env `CONFIGOR_DEBUG_MODE` to true when running your application
	configor.New(&configor.Config{Debug: false, Verbose: false}).Load(&Config, "config.yml")
	fmt.Printf("config: %+v", Config)

	//$ go run main.go
	// Will load `config.json`, `config.development.json` if it exists
	// `config.development.json` will overwrite `config.json`'s configuration
	// You could use this to share same configuration across different environments

	//$ CONFIGOR_ENV=production go run main.go
	// Will load `config.json`, `config.production.json` if it exists
	// `config.production.json` will overwrite `config.json`'s configuration

	//$ go test
	// Will load `config.json`, `config.test.json` if it exists
	// `config.test.json` will overwrite `config.json`'s configuration

	//$ CONFIGOR_ENV=production go test
	// Will load `config.json`, `config.production.json` if it exists
	// `config.production.json` will overwrite `config.json`'s configuration

	// With Flags
	// todo https://github.com/jinzhu/configor
}
